<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>发放学生奖金</title>
        <link rel="stylesheet" href="../../layui/css/layui.css">
    </head>
    <body>

        <!-- 发放学生奖金模板 -->
        <div id="grantStu">

            <form class="layui-form" action="javascript:;">

                <div class="layui-form-item">
                    <input  type="hidden" id="studentId" name="studentId"/>
                    <input  type="hidden" id="studentName" name="studentName"/>
                    <label class="layui-form-label">发放原因：</label>
                    <div class="layui-input-inline">
                        <input name="bonusRemark" required  lay-verify="required" placeholder="请输入奖金备注" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label">发放金额：</label>
                    <div class="layui-input-inline">
                        <input name="bonusMonsy" required  lay-verify="required" placeholder="请输入发放金额" autocomplete="off" class="layui-input">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label"></label>
                    <div class="layui-input-inline">
                        <button class="layui-btn" lay-submit lay-filter="addGrant">
                            确定
                        </button>
                    </div>
                </div>

            </form>

        </div>

    </body>

    <script src="../../js/jquery-3.6.0.js"></script>
    <script src="../../layui/layui.js"></script>
    <script>
        layui.use('form',function (){
            var form = layui.form;


            form.on('submit(addGrant)',function (d){
                console.log(d.field)

                //发送ajax 为学生发放奖金
                $.ajax({
                    type:'post',
                    url:'/addBonus',
                    data:d.field,
                    dataType:'json',
                    success:function (res){
                        if (res.state == '200'){
                            layer.msg('学生奖金发放成功', {time: 1500, icon: 6}, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.location.reload(); //刷新父页面
                                parent.layer.close(index);
                            })
                        }else {
                            layer.msg('出现异常，发放失败', {time: 1000, icon: 5}, function () {
                                var index = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(index);
                            })
                        }
                    },
                    error:function (e){
                        console.log('请求失败')
                    }
                })
            })
        })
    </script>
</html>